package com.wanmait.deliverymangementsystem.managecontroller;

import com.wanmait.deliverymangementsystem.pojo.Users;
import com.wanmait.deliverymangementsystem.service.UsersService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("manage")
public class ManageUsersControlller {
    @Resource
    private UsersService usersService;
    @GetMapping("userList")
    @ModelAttribute("userList")
    public List<Users> userList(){
      List<Users> userList=usersService.findAll();
        return  userList;
    }
    @CrossOrigin
    @GetMapping("userlistvue")
    @ResponseBody
   public  List<Users> userlistvue(){
        List<Users> userList=usersService.findAll();
        return  userList;
    }
    @GetMapping("banUser")
    public String banUser(Integer id,Boolean status){
        usersService.banUser(id,status);
        return "redirect:/manage/userList";
    }
    @GetMapping("searchUser")
    @ResponseBody
    public Map<String, Object> searchUser(String name, String phone, String email){
        System.out.println("name = " + name + ", phone = " + phone + ", email = " + email);
       List<Users>userList= usersService.search(name,phone,email);
        Map<String, Object> response = new HashMap<>();
        response.put("userList", userList);
        System.out.println(userList);
        return response;

    }
}
